home *** CD-ROM | disk | FTP | other *** search
/ PC World 2007 January / PCWorld_2007-01_cd.bin / v cisle / hotkey / AutoHotkey104504_Install.exe / Extras / Generate TextPad.ahk < prev    next >
Text File  |  2005-02-22  |  4KB  |  154 lines

  1. ;___________________________________________
  2.  
  3. ;     TextPad Syntax Generator Script
  4. ;               -Rajat
  5. ;___________________________________________
  6.  
  7. SetBatchLines, -1     ; Speeds up file operations.
  8. SetWorkingDir, ..\..  ; Set it to the Editors folder.
  9.  
  10. TargetFile = TextPad\AutoHotkey.syn
  11. FileDelete, %TargetFile%
  12.  
  13. FileAppend, `; TextPad keyword syntax file for AutoHotkey`n, %TargetFile%
  14. FileAppend, `; Auto generated by Rajat's TextPad Syntax Generator Script`n`n, %TargetFile%
  15.  
  16. FileAppend, C=1`n`n, %TargetFile%
  17.  
  18. FileAppend, [Syntax]`n, %TargetFile%
  19. FileAppend, Namespace1 =`n, %TargetFile%
  20. FileAppend, IgnoreCase = Yes`n, %TargetFile%
  21. FileAppend, `;BracketChars = {}`n, %TargetFile%
  22. FileAppend, OperatorChars = +-*/<>=`n, %TargetFile%
  23. FileAppend, PreprocStart =`n, %TargetFile%
  24. FileAppend, SyntaxStart =`n, %TargetFile%
  25. FileAppend, SyntaxEnd =`n, %TargetFile%
  26. FileAppend, CommentStart = /*`n, %TargetFile%
  27. FileAppend, CommentEnd = */`n, %TargetFile%
  28. FileAppend, CommentStartAlt =`n, %TargetFile%
  29. FileAppend, CommentEndAlt =`n, %TargetFile%
  30. FileAppend, SingleComment = `;`n, %TargetFile%
  31.  
  32. ; Not desirable because it prevents comments on the same line as a command from being highlighted as a comment:
  33. ;FileAppend, SingleCommentCol = Leading`n, %TargetFile%
  34.  
  35. FileAppend, SingleCommentEsc = ```n, %TargetFile%
  36. FileAppend, StringsSpanLines = No`n, %TargetFile%
  37. FileAppend, StringStart = `%`n, %TargetFile%
  38. FileAppend, StringEnd = `%`n, %TargetFile%
  39. FileAppend, StringAlt = "`n, %TargetFile%
  40. FileAppend, StringEsc = ```n, %TargetFile%
  41. FileAppend, CharStart =`n, %TargetFile%
  42. FileAppend, CharEnd =`n, %TargetFile%
  43. FileAppend, CharEsc = ```n, %TargetFile%
  44. FileAppend, `n, %TargetFile%
  45.  
  46. FileAppend, [Keywords 1]`n, %TargetFile%
  47.  
  48.  
  49. ;this doesn't require fancy cmd names for human reading,
  50. ;it just requires names to be highlighted. so getting first name only
  51.  
  52. Loop, Read, Syntax\Commands.txt, %TargetFile%
  53. {
  54.     CurrCmd =
  55.     FullCmd = %a_loopreadline%
  56.     
  57.     ;directives don't have first comma but a first space
  58.     ;so whichever is first, take it as end of cmd name
  59.     StringGetPos, cPos, a_loopreadline, `,
  60.     StringGetPos, sPos, a_loopreadline, %A_Space%
  61.     
  62.     IfLess, sPos, %cPos%
  63.         IfGreater, sPos, 0
  64.             StringLeft, CurrCmd, a_loopreadline, %sPos%
  65.     
  66.     IfLess, cPos, %sPos%
  67.         IfGreater, cPos, 0
  68.             StringLeft, CurrCmd, a_loopreadline, %cPos%
  69.  
  70.     IfLess, cPos, %sPos%
  71.         IfLess, cPos, 0
  72.             StringLeft, CurrCmd, a_loopreadline, %sPos%
  73.  
  74.     IfLess, sPos, %cPos%
  75.         IfLess, sPos, 0
  76.             StringLeft, CurrCmd, a_loopreadline, %cPos%
  77.             
  78.     StringReplace, FullCmd, FullCmd, ``n, `n, a
  79.     StringReplace, FullCmd, FullCmd, ``t, `t, a
  80.  
  81.     StringReplace, CurrCmd, CurrCmd, [,, a
  82.     StringReplace, CurrCmd, CurrCmd, %a_space%,, a
  83.     
  84.     ;For a directive that has no parameters
  85.     IfEqual, CurrCmd,
  86.         CurrCmd = %a_loopreadline%
  87.     
  88.     
  89.     ;this check removes duplicates for loop and if
  90.     IfNotEqual, CurrCmd, %LastCmd%
  91.         FileAppend, %CurrCmd%`n
  92.     
  93.     LastCmd = %CurrCmd%
  94. }
  95.  
  96.  
  97. FileAppend, `n[Keywords 2]`n, %TargetFile%
  98.  
  99. ;Adding keywords including the blank lines and comments
  100. Loop, Read, Syntax\Keywords.txt, %TargetFile%
  101.     FileAppend, %A_LoopReadLine%`n
  102.  
  103. FileAppend, `n`n, %TargetFile%
  104.  
  105. ;same with variables
  106. Loop, Read, Syntax\Variables.txt, %TargetFile%
  107.     FileAppend, %A_LoopReadLine%`n
  108.  
  109.  
  110.  
  111. FileAppend, `n[Keywords 3]`n, %TargetFile%
  112.  
  113. ;keys are added with and without {}
  114. Loop, Read, Syntax\Keys.txt, %TargetFile%
  115. {
  116.     FileAppend, %A_LoopReadLine%`n
  117.     IfEqual, A_LoopReadLine,, Continue
  118.     
  119.     ;comment check
  120.     StringReplace, check, A_LoopReadLine, %A_Space%,, A
  121.     StringReplace, check, check, %A_Tab%,, A
  122.     StringLeft, check, check, 1
  123.     IfEqual, check, `;, Continue
  124.     
  125.     FileAppend, {%A_LoopReadLine%}`n
  126. }
  127.     
  128.  
  129.  
  130. ;Now generating the ClipLibrary
  131. TargetFile = TextPad\AutoHotkey.tcl
  132.  
  133. FileDelete, %TargetFile%
  134.  
  135. FileAppend, !TCL=3468`, Auto-generated by Rajat's TextPad Syntax Generator Script`n, %TargetFile%
  136. FileAppend, !TITLE=AutoHotkey`n, %TargetFile%
  137. FileAppend, !SORT=Y`n, %TargetFile%
  138.  
  139.  
  140.  
  141. ;adding commands
  142. Loop, Read, Syntax\Commands.txt, %TargetFile%
  143. {
  144.     FileReadLine, CmdName, Syntax\CommandNames.txt, %A_Index%
  145.     StringReplace, FullCmd, A_LoopReadLine, ``n, `n, a
  146.     StringReplace, FullCmd, FullCmd, ``t, %A_Tab%, a
  147.     
  148.     FileAppend, !TEXT=%CmdName%`n%FullCmd%`n!`n
  149. }
  150.  
  151. ;adding variables
  152. Loop, Read, Syntax\Variables.txt, %TargetFile%
  153.     FileAppend, !TEXT=%A_LoopReadLine%`n%A_LoopReadLine%`n!`n
  154.